<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="./widget/base"></div>
</head>
<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'west',split:true" style="width:40%">
        <div id="viewMenuCategoryToolbar">
            <nimrod:security authority="/COMPONENT/USER/VIEW_MENU/PAGE_ALL/VIEW_MENU_CATEGORY_ADD_DIALOG">
                <a href="javascript:" class="easyui-linkbutton" iconCls="iconfont icon-plus"
                   onclick="viewMenuCategoryAddDialog();">新增</a>
            </nimrod:security>
            <nimrod:security authority="/COMPONENT/USER/VIEW_MENU/PAGE_ALL/VIEW_MENU_CATEGORY_EDIT_DIALOG">
                <a href="javascript:" class="easyui-linkbutton" iconCls="iconfont icon-edit"
                   onclick="viewMenuCategoryEditDialog();">编辑</a>
            </nimrod:security>
            <nimrod:security authority="/COMPONENT/USER/VIEW_MENU/PAGE_ALL/VIEW_MENU_CATEGORY_DELETE_ALL">
                <a href="javascript:" class="easyui-linkbutton" iconCls="iconfont icon-close"
                   onclick="viewMenuCategoryDeleteAll();">删除</a>
            </nimrod:security>
        </div>
        <table id="viewMenuCategory"></table>
    </div>
    <div data-options="region:'center',split:true">
        <div id="viewMenuToolbar">
            <nimrod:security authority="/COMPONENT/USER/VIEW_MENU/PAGE_ALL/VIEW_MENU_ADD_DIALOG">
                <a href="javascript:" class="easyui-linkbutton" iconCls="iconfont icon-plus"
                   onclick="viewMenuAddDialog();">新增</a>
            </nimrod:security>
            <nimrod:security authority="/COMPONENT/USER/VIEW_MENU/PAGE_ALL/VIEW_MENU_EDIT_DIALOG">
                <a href="javascript:" class="easyui-linkbutton" iconCls="iconfont icon-edit"
                   onclick="viewMenuEditDialog();">编辑</a>
            </nimrod:security>
            <nimrod:security authority="/COMPONENT/USER/VIEW_MENU/PAGE_ALL/VIEW_MENU_DELETE_ALL">
                <a href="javascript:" class="easyui-linkbutton" iconCls="iconfont icon-close"
                   onclick="viewMenuDeleteAll();">删除</a>
            </nimrod:security>
        </div>
        <table id="viewMenu"></table>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        var columns = [
            {field: 'checkbox', checkbox: true},
            {field: 'id', title: 'ID'},
            {field: 'name', title: '分类名称'},
            {field: 'icon', title: '图标（icon）'},
            {field: 'sort', title: '排序'},
            {field: 'remark', title: '备注'},
            {field: 'gmtModified', title: '更新时间'},
            {field: 'gmtCreated', title: '创建时间'}
        ];

        $('#viewMenuCategory').treegrid(expressui.grid.create, {
            title: '视图菜单分类',
            url: Url.User.Api.VIEW_MENU_CATEGORY + '/list_all_parent',
            expandUrl: Url.User.Api.VIEW_MENU_CATEGORY + '/list_all_by_parent_id?parentId={id}',
            columns: [columns],
            onCheck: function (row) {
                if (row) {
                    $('#viewMenu').datagrid('reload', Url.User.Api.VIEW_MENU + '/page_all_by_view_menu_category_id?viewMenuCategoryId=' + row.id);
                }
            },
            onUncheck: function (index, row) {
                $('#viewMenu').datagrid('loadData', []);
            }

        });
        columns = [
            {field: 'checkbox', checkbox: true},
            {field: 'id', title: 'ID'},
            {field: 'name', title: '菜单名称'},
            {field: 'icon', title: '图标（icon）'},
            {field: 'url', title: '请求地址（url）'},
            {field: 'sort', title: '排序'},
            {field: 'remark', title: '备注'},
            {field: 'gmtModified', title: '更新时间'},
            {field: 'gmtCreated', title: '创建时间'}
        ];
        $('#viewMenu').datagrid(expressui.grid.create, {
            title: '视图菜单',
            columns: [columns]
        });
    });

    function viewMenuCategoryAddDialog() {
        var one = $('#viewMenuCategory').treegrid(expressui.grid.getCheckedOneNoCheckedOrShowAlert);
        if (!one) {
            return;
        }
        $('#viewMenuCategoryAddDialog').dialog(expressui.dialog.create, {
            title: '新增视图菜单分类',
            grid: {type: 'treegrid', selector: '#viewMenuCategory'},
            href: Url.User.Page.VIEW_MENU_CATEGORY + '/add_dialog',
            get: {url: Url.User.Api.VIEW_MENU_CATEGORY + '/one/{id}', method: 'get'},
            save: {url: Url.User.Api.VIEW_MENU_CATEGORY + '/add_one', method: 'post'},
            buttons: [{
                text: '保存',
                iconCls: 'iconfont icon-save',
                handler: expressui.dialog.add,
                reload: [{type: 'treegrid', selector: '#viewMenuCategory'}, {
                    type: 'datagrid',
                    selector: '#viewMenu',
                    data: []
                }],
                success: '新增成功'
            }, {
                text: '关闭',
                iconCls: 'iconfont icon-close',
                handler: expressui.dialog.close
            }]
        });
    }

    function viewMenuCategoryEditDialog() {
        var one = $('#viewMenuCategory').treegrid(expressui.grid.getCheckedOneOrShowAlert);
        if (one) {
            $('#viewMenuCategoryEditDialog').dialog(expressui.dialog.create, {
                title: '编辑视图菜单分类',
                grid: {type: 'treegrid', selector: '#viewMenuCategory'},
                href: Url.User.Page.VIEW_MENU_CATEGORY + '/edit_dialog',
                get: {url: Url.User.Api.VIEW_MENU_CATEGORY + '/one/{id}', method: 'get'},
                save: {url: Url.User.Api.VIEW_MENU_CATEGORY + '/save_one', method: 'post'},
                buttons: [{
                    text: '保存',
                    iconCls: 'iconfont icon-save',
                    handler: expressui.dialog.save,
                    reload: [{type: 'treegrid', selector: '#viewMenuCategory'}, {
                        type: 'datagrid',
                        selector: '#viewMenu',
                        data: []
                    }],
                    success: '保存成功'
                }, {
                    text: '关闭',
                    iconCls: 'iconfont icon-close',
                    handler: expressui.dialog.close
                }]
            });
        }
    }

    function viewMenuCategoryDeleteAll() {
        $('#viewMenuCategory').treegrid(expressui.grid.postCheckedLessOneOrShowAlert, {
            url: Url.User.Api.VIEW_MENU_CATEGORY + '/delete_all',
            method: 'post',
            success: '删除成功',
            reload: [{type: 'treegrid', selector: '#viewMenuCategory'}, {
                type: 'datagrid',
                selector: '#viewMenu',
                data: []
            }]
        });
    }

    function viewMenuAddDialog() {
        var one = $('#viewMenuCategory').treegrid(expressui.grid.getCheckedOneOrShowAlert);
        if (!one) {
            return;
        }
        $('#viewMenuAddDialog').dialog(expressui.dialog.create, {
            title: '新增视图菜单',
            width: 460,
            grid: {type: 'treegrid', selector: '#viewMenuCategory'},
            href: Url.User.Page.VIEW_MENU + '/add_dialog',
            get: {url: Url.User.Api.VIEW_MENU + '/one/{id}', method: 'get'},
            save: {url: Url.User.Api.VIEW_MENU + '/add_one', method: 'post'},
            buttons: [{
                text: '保存',
                iconCls: 'iconfont icon-save',
                handler: expressui.dialog.add,
                reload: [{type: 'datagrid', selector: '#viewMenu'}],
                success: '新增成功'
            }, {
                text: '关闭',
                iconCls: 'iconfont icon-close',
                handler: expressui.dialog.close
            }]
        });
    }

    function viewMenuEditDialog() {
        var one = $('#viewMenu').datagrid(expressui.grid.getCheckedOneOrShowAlert);
        if (one) {
            $('#viewMenuEditDialog').dialog(expressui.dialog.create, {
                title: '编辑视图菜单分类',
                grid: {type: 'datagrid', selector: '#viewMenu'},
                href: Url.User.Page.VIEW_MENU + '/edit_dialog',
                get: {url: Url.User.Api.VIEW_MENU + '/one/{id}', method: 'get'},
                save: {url: Url.User.Api.VIEW_MENU + '/save_one', method: 'post'},
                buttons: [{
                    text: '保存',
                    iconCls: 'iconfont icon-save',
                    handler: expressui.dialog.save,
                    reload: [{type: 'datagrid', selector: '#viewMenu'}],
                    success: '保存成功'
                }, {
                    text: '关闭',
                    iconCls: 'iconfont icon-close',
                    handler: expressui.dialog.close
                }]
            });
        }
    }

    function viewMenuDeleteAll() {
        $('#viewMenu').datagrid(expressui.grid.postCheckedLessOneOrShowAlert, {
            url: Url.User.Api.VIEW_MENU + '/delete_all?roleId=' + roleId,
            method: 'post',
            success: '删除成功',
            reload: {type: 'datagrid', selector: '#viewMenu'}
        });
    }
</script>
</body>
</html>